<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/12/27
 * Time: 10:06
 */
namespace app\province\controller;
use think\Controller;
use think\Db;
class Login extends Controller
{
    //厂家登录页面
    public function index(){
        return $this->fetch('/login');
    }

    //验证密码和账号
    public function doLogin(){
        extract(input());
        $hasUser = Db::name('province')
            ->where('p_account',$username)
            ->find();
        if(empty($hasUser)){
            return json(['code' => -1, 'url' => '', 'msg' => '省级管理员不存在',"status"=>100]);
        }
        if(md5($password) != $hasUser['p_password']){
            return json(['code' => -2, 'url' => '', 'msg' => '密码错误',"status"=>100]);
        }
        session('p_uid',$hasUser['p_id']);
        session('p_username',$hasUser['p_username']);
        session('p_account',$hasUser['p_account']);
        session('p_area',$hasUser['p_range']);
        session('p_area',$hasUser['p_range']);
        return json(['code' => 1, 'url' => url('province/Index/index'), 'msg' => '登录成功！']);
    }
    //退出操作
    public function loginOut()
    {
        session(null);
        $this->redirect(url('province/index/index'));
    }

}